<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hash Event Test</title>
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
</head>

<body>

<script>

var HashAddress = {};
HashAddress._isGlobalListenerSet = false;
HashAddress._intervalID = false;
HashAddress._hashchangecheck = function(){
	if( this._currentHash != window.location.hash ){
		this._currentHash = window.location.hash;
		HashAddress.fireEvents('change',[this._currentHash]);
	}
};
HashAddress._globalListener = function(){
	if( "onhashchange" in window ){
		window.onhashchange = function(e){
			HashAddress.fireEvents('change',[window.location.hash]);
		}
	} else {
		this._intervalID = window.setInterval(this._hashchangecheck, 100, HashAddress );
	}
	this._isGlobalListenerSet = true;
};
HashAddress.setValue = function(v){ window.location.hash = v; }
HashAddress._events = {
	'change':[]
};

HashAddress.addEvent = function(name, fn){
	HashAddress._events[name].push(fn);
	if(!this._isGlobalListenerSet){
		HashAddress._globalListener();
	}
};

HashAddress.removeEvents = function(name, fn){
	HashAddress._events[name].length = 0;
};

HashAddress.fireEvents = function(name, arg){
	var events = HashAddress._events[name];
	var eChange = new HashAddress.Event.Change(arg);
	for (var i = 0, l = events.length; i < l; i++){
		if (i in events){ events[i].call(events[i], eChange ); }
	}
};

HashAddress.Event = function(type){
	this.type = type;
};
HashAddress.Event.prototype = {'type':'','hash':'','timestamp':0};

HashAddress.Event.Change = function(arg){
	this.timestamp = new Date().getTime();
	this.hash = arg[0];
};
HashAddress.Event.Change.prototype = new HashAddress.Event('hashchange');

// Gaia compatibility
var SWFAddress = {
	'setValue':HashAddress.setValue
};


window.onload = function(){
	HashAddress.addEvent('change',function(e){
		console.log(e);
	});
	
	
	
}

 
function A(){ this._a = 'a'; }
A.prototype = {'_a':'b'};
A.prototype.log = function(){
	var proto = this.__proto__ || this.constructor.prototype;
	console.log(proto);
}
function B(){ // this._b = 'a'; 
}
B.prototype = new A();
B.prototype['_b'] = 'b';

var x = new B();

x.log();

</script>


<button onclick="HashAddress.setValue('hash_'+new Date().toUTCString());">Change Event</button>
</body>
</html>
